// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
const { contextBridge, ipcRenderer } = require('electron');

// 向渲染进程暴露配置相关的API
contextBridge.exposeInMainWorld('appConfig', {
  getConfig: () => ipcRenderer.sendSync('get-config'),
  onConfigUpdated: (callback) => {
    ipcRenderer.on('config-updated', (event, config) => callback(config));
    return () => ipcRenderer.removeAllListeners('config-updated');
  }
});

// 监听主进程发送的配置
ipcRenderer.on('config-loaded', (event, config) => {
  // 可以在这里处理初始配置
  console.log('渲染进程收到配置:', config);
});
